define([], function(require, exports) {
    exports.ready = function(hashCode, data, cite) {
        // 注册该功能要用到的数据字典
        yufp.lookup.reg('DATA_STS,SYS_TYPE,SEX_TYPE,SCENE_TYPE,APPROVAL_STATUS,CARD_TYPE,CUST_LEVEL,BIG_BLG_IDY,BIG_OCP_CD');
        var orgId = '';
        var roleCode = '';
        for (var i = 0; i < yufp.session.roles.length; i++) {
            if (yufp.session.roles[i].checked != null) {
                roleCode = yufp.session.roles[i].code;
            }
        }
        // 创建virtual model
        yufp.custom.vue({
            el: '#processApproval',
            // 以m_开头的属性为UI数据不作为业务数据，否则为业务数据
            data: function() {
                var me = this;
                return {
                    processApprovalInfo: {},
                    messageFormInfo: {},
                    processApprovalRules: {
                        address: [{
                            required: true,
                            message: '必填项',
                            trigger: 'blur'
                        }],
                        ctfNo: [{
                            required: true,
                            message: '必填项',
                            trigger: 'blur'
                        }]
                    },
                    processApprovalDialogVisible: false,
                    rules: {
                        ctfTp: [{
                            required: true,
                            message: '必填项',
                            trigger: 'blur'
                        }],
                        ctfNo: [{
                            required: true,
                            message: '必填项',
                            trigger: 'blur'
                        }],
                        custName: [{
                            required: true,
                            message: '必填项',
                            trigger: 'blur'
                        }],
                        address: [{
                            required: true,
                            message: '必填项',
                            trigger: 'blur'
                        }],
                        mobNo: [{
                            required: true,
                            message: '必填项',
                            trigger: 'blur'
                        }],
                    },
                    processData: {
                        condition: JSON.stringify({
                            userId: yufp.session.userId,
                            orgId: yufp.session.user.org.code,
                        })
                    },
                    processDataUrl: backend.msmFrontWebService + '/api/processApproval/getApprovalInformation',
                    uploadData: {
                        condition: JSON.stringify({
                            userId: yufp.session.userId,
                            orgId: yufp.session.orgId,
                        })
                    },
                    headers: {
                        'Authorization': 'Bearer' + yufp.service.getToken()
                    },
                    importDialogVisible: false,
                    dialogFormVisible: false,
                    messageFormVisible: false,
                    dialogStatus: '',
                    saveBtnShow: '',
                    formDisabled: false,
                    nowRow: null,
                    dialogDisabled: true,
                    activeName: ['1', '2'], // 默认显示name为1的
                    textMap: {
                        detail: "客户基本信息",
                    },
                    loading: false,
                    uploadAction: '/api/CustCenter/uploadExcel',
                    modFields: [{
                        columnCount: 4,
                        fields: [{
                            field: 'custName',
                            placeholder: "客户名称",
                            label: "客户名称",
                        }, {
                            field: 'ctfTp',
                            placeholder: "证件类型",
                            label: "证件类型",
                            type: 'select',
                            dataCode: 'CARD_TYPE',
                            rules: [{
                                required: true,
                                message: "必填项",
                                trigger: 'blur'
                            }]
                        },
                            {
                                field: 'ctfNo',
                                placeholder: "请选择",
                                label: "证件号码",
                                rules: [{
                                    required: true,
                                    message: "必填项",
                                    trigger: 'blur'
                                }]
                            }, {
                                field: 'gndrCd',
                                placeholder: "请选择",
                                label: "性别",
                                type: 'select',
                                dataCode: 'SEX_TYPE',
                            },
                            {
                                field: 'ocpCd',
                                placeholder: "请选择",
                                label: "职业",
                                type: 'select',
                                dataCode: this.dialogStatus === 'edit' ? 'OCP_CD' : 'BIG_OCP_CD'
                            },
                            {
                                field: 'mobNo',
                                placeholder: "手机号码",
                                label: "手机号码",
                                rules: [{
                                    required: true,
                                    message: "必填项",
                                    trigger: 'blur'
                                }]
                            }
                        ]
                    },
                        {
                            columnCount: 1,
                            fields: [{
                                field: 'address',
                                placeholder: "联系地址",
                                label: "联系地址",
                                rules: [{
                                    required: true,
                                    message: "必填项",
                                    trigger: 'blur'
                                }]
                            }]
                        },
                        {
                            columnCount: 1,
                            fields: [{
                                field: 'entpIdyCgy',
                                placeholder: "请选择",
                                label: "行业",
                                type: 'select',
                                dataCode: 'BIG_BLG_IDY',
                            }]
                        }
                    ],

                };
            },
            computed: {
                action: function() {
                    var _this = this;
                    return yufp.service.getUrl({
                        url: _this.uploadAction
                    });
                }
            },
            // 钩子
            mounted: function() {},
            methods: {
                searchFn: function() {
                    var me = this;
                    var param = {
                        condition: JSON.stringify({
                            custName: me.$refs.customerInfoSearch.formdata.custName,
                            // userName: me.$refs.customerInfoSearch.formdata.userName,
                            custLevel: me.$refs.customerInfoSearch.formdata.custLevel,
                        })
                    };
                    me.$refs.processTable.remoteData(param);
                },
                lookupProcessInformation: function() {
                    var _this = this;
                    if (this.$refs.processTable.selections.length !== 1) {
                        this.$message({
                            message: '请选择一个选项',
                            type: 'warning'
                        });
                        return;
                    }
                    if (this.$refs.processTable.selections[0].approvalType ==="2"){
                        _this.switchStatus('detail','dialogFormVisible', false);
                        yufp.service.request({
                            url: backend.msmFrontWebService + '/api/processApproval/getApprovalDetail',
                            method: 'get',
                            data: {
                                condition: JSON.stringify({
                                    userId: yufp.session.userId,
                                    nodeId: this.$refs.processTable.selections[0].nodeId,
                                })
                            },
                            callback: function(code, message, response) {
                                if (code === 0) {
                                    _this.processApprovalInfo.custName = response.data[0].custName;
                                    _this.processApprovalInfo.ctfNo = response.data[0].ctfNo;
                                    _this.processApprovalInfo.address = response.data[0].address;
                                    _this.processApprovalInfo.sponsorName = response.data[0].sponsorName;
                                    _this.processApprovalInfo.crtDt = response.data[0].crtDt;
                                }
                            }
                        });
                    }
                    if (this.$refs.processTable.selections[0].approvalType ==="1"){
                        _this.switchStatus('detail','messageFormVisible', false);
                        yufp.service.request({
                            url: backend.msmFrontWebService + '/api/processApproval/getMessageDetail',
                            method: 'get',
                            data: {
                                condition: JSON.stringify({
                                    userId: yufp.session.userId,
                                    nodeId: this.$refs.processTable.selections[0].nodeId,
                                })
                            },
                            callback: function(code, message, response) {
                                if (code === 0) {
                                    _this.messageFormInfo.promoterName = response.data[0].promoterName;
                                    _this.messageFormInfo.content = response.data[0].content;
                                } else {}
                            }
                        });
                    }

                },
                //每次执行显示操作，新增操作执行清空，修改执行查询，
                restInputValue: function() {
                    var _this = this;
                    _this.dialogFormVisible = false;
                    _this.messageFormVisible = false;
                    _this.$nextTick(function() {
                        if (_this.$refs.processApprovalForm) {
                            _this.$refs.processApprovalForm.resetFields();
                        }if (_this.$refs.messageForm) {
                            _this.$refs.messageForm.resetFields();
                        }
                    });
                },
                //点击按钮后，将该消息变成审核通过状态，并且将地址更新
                adoptFn: function(row) {
                    var _this = this;
                    if (row.approvalType == "1") { //短信审批流程
                        yufp.service.request({
                            url: '/api/marketCustGroup/approveSendMessage',
                            method: 'post',
                            data: {
                                promoterName:row.promoterName,
                                promoterId:row.promoterId,
                                userId: yufp.session.userCode,
                                userName: yufp.session.userName,
                                nodeId: row.nodeId,
                                id: row.id,
                                content: row.content,
                                custMgrId: row.custMgrId,
                                roleCode: roleCode,
                                orgId: yufp.session.org.id,
                            },
                            callback: function(code, message, response) {
                                if (code === 0) {
                                    _this.$refs.processTable.remoteData();
                                    _this.$message({
                                        message: '操作成功',
                                        type: 'success'
                                    });
                                } else {
                                    _this.$message({
                                        message: response.data,
                                        type: 'success'
                                    });
                                }
                            }
                        });
                    } else {
                        yufp.service.request({
                            url: backend.msmFrontWebService + '/api/processApproval/adoptProcess',
                            method: 'get',
                            data: {
                                condition: JSON.stringify({
                                    userId:yufp.session.userId,
                                    nodeId:row.nodeId,
                                })
                            },
                            callback: function (code, message, response) {
                                if (code ===0){
                                    _this.$refs.processTable.remoteData();
                                    _this.$message({message: '操作成功', type: 'success'});
                                }
                                else {
                                    _this.$message({message: response.data, type: 'success'});
                                }
                            }
                        });
                    }
                },
                //点击拒绝按钮后，将审核状态变为未通过状态
                refuseFn: function(row) {
                    var _this = this
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/processApproval/refuseProcess',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                userId: yufp.session.userId,
                                nodeId: row.nodeId,
                            })
                        },
                        callback: function(code, message, response) {
                            if (code === 0) {
                                _this.$refs.processTable.remoteData();
                                _this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                            } else {
                                _this.$message({
                                    message: response.data,
                                    type: 'success'
                                });
                            }

                        }
                    });
                },
                closeDialog: function() {
                    if (this.$refs.processApprovalForm){
                        this.$refs.processApprovalForm.resetFields();
                    }
                    if (this.$refs.messageForm){
                        this.$refs.messageForm.resetFields();
                    }
                    this.dialogFormVisible = false;
                    this.messageFormVisible = false;
                },
                switchStatus: function(viewType,witchForm,editable) {
                    var _this = this;
                    _this.dialogStatus = viewType;
                    _this.saveBtnShow = editable;
                    if (witchForm === "dialogFormVisible"){
                        _this.dialogFormVisible = true;
                    }
                    if (witchForm === "messageFormVisible"){
                        _this.messageFormVisible = true;
                    }
                    _this.formDisabled = !editable;
                },
            }
        });
    };

    // 消息处理
    exports.onmessage = function(type, message) {};

    // page销毁时触发destroy方法
    exports.destroy = function(id, cite) {};
});
